class ScorePanel {
  score = 0;
  level = 1;
  // 等级上限设置
  maxLevel: number;
  // 多少分升一级
  upScore: number;
  scoreElement: HTMLElement;
  levelElement: HTMLElement;
  constructor(maxLevel: number = 10, upScore: number = 10) {
    this.maxLevel = maxLevel;
    this.upScore = upScore;
    this.scoreElement = document.querySelector("#score")!;
    this.levelElement = document.querySelector("#level")!;
  }

  // 设置一个加分的方法
  addScore() {
    // 使分数自增
    this.scoreElement.innerHTML = ++this.score + "";
    if (this.score % this.upScore === 0) this.levelUp();
  }

  // 提升等级方法
  levelUp() {
    if (this.level >= this.maxLevel) return;
    this.levelElement.innerHTML = ++this.level + "";
  }
}

export default ScorePanel;